<?php

	if ($_SESSION['Level'] == "HRD")
	{
		echo 	"
			<a href='index.php?Content=InputKaryawan' ><img src='image/adduser.gif'>Tambah Karyawan<a><br>
			";
		// Menampilkan data karyawan
		echo 	"	
				<table border=2 cellpadding=10>
				<tr>
				<td colspan=8  align='center'><h3>Daftar Karyawan</h3></td>
				</tr>
				<tr align='center'>
				<td>No</td>
				<td>Nama Lengkap</td>
				<td>Jabatan</td>
				<td>Unit Kerja</td>
				<td>Tanggal Masuk Kerja</td>
				<td>Jatah Cuti</td>
				<td>Level</td>
				<td>-</td>
				</tr>";
		if(ISSET($_GET['Halaman']))
		{
		// Data Paging
		$halaman=$_GET['Halaman'];
		}
		$batas=10;
		if(empty($halaman))
		{
			$posisi=0;
			$halaman=1;
		}
		else
		{
			$posisi = ($halaman-1) * $batas;
		}
		// Mengambil data seluruh karyawan
		$DataKaryawan = mysql_query("SELECT * FROM d_karyawan ORDER BY nama_lengkap ASC limit $posisi,$batas");
				
			$No = $No = $posisi+1;
			while ($Data1 = mysql_fetch_array($DataKaryawan))
			{
			echo 	"
					<tr>
					<td>$No.</td>
					<td>$Data1[nama_lengkap]</td>
					<td>$Data1[jabatan]</td>
					<td>$Data1[unit_kerja]</td>
					<td>$Data1[tgl_masuk_kerja]</td>
					<td>$Data1[jatah_cuti]</td>
					<td>$Data1[level]</td>
					<td>	<a href = 'index.php?Content=EditDataKaryawan&IdKaryawan=$Data1[id_karyawan]'> Edit </a> <br>
							<a href = 'proses.php?HapusKaryawan=$Data1[id_karyawan]'> Hapus </a>	</td>
					</tr>";
				$No++;
			}
			echo "</table>";
			
			$file="index.php?Content=DataKaryawan";

			$tampil2="SELECT * FROM d_karyawan";
			$hasil2=mysql_query($tampil2);
			$jmldata=mysql_num_rows($hasil2);

			$jmlhalaman=ceil($jmldata/$batas);


			//link ke halaman sebelumnya (previous)
			if($halaman > 1)
			{
				$previous=$halaman-1;
				echo "<A HREF=$file&Halaman=1><< First</A> | 
					<A HREF=$file&Halaman=$previous>< Previous</A> | ";
			}
			else
			{ 
				echo "<< First | < Previous | ";
			}
			
			// Untuk angka pada halaman
			$angka=($halaman > 3 ? " ... " : " ");
			for($i=$halaman-2;$i<$halaman;$i++)
			{
			  if ($i < 1) 
				  continue;
			  $angka .= "<a href=$file&Halaman=$i> $i </A> ";
			}

			$angka .= " <b>$halaman</b> ";
			for($i=$halaman+1;$i<($halaman+3);$i++)
			{
			  if ($i > $jmlhalaman) 
				  break;
			  $angka .= "<a href=$file&Halaman=$i> $i </A> ";
			}

			$angka .= ($halaman+2<$jmlhalaman ? " ...  
					  <a href=$file&Halaman=$jmlhalaman>$jmlhalaman</A> " : " ");

			echo "$angka";

			//link kehalaman berikutnya (Next)
			if($halaman < $jmlhalaman)
			{
				$next=$halaman+1;
				echo " | <A HREF=$file&Halaman=$next>Next ></A> | 
			  <A HREF=$file&Halaman=$jmlhalaman>Last >></A> ";
			}
			else
			{ 
				echo " | Next > | Last >>";
			}
			echo 	"
					<p>Jumlah <b>$jmldata</b> karyawan</p>
					";
	}
	
?>